package com.mixsmart.core.service.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mixsmart.core.bean.Paginate;
import com.mixsmart.core.bean.entity.IEntityBean;
import com.mixsmart.core.dao.IBaseEntityDao;
import com.mixsmart.core.service.IBaseService;
import com.mixsmart.core.service.IQueryService;
import com.mixsmart.spellsql.ICondition;

/**
 * 基础服务类的实现类
 * @author lmq 2016年1月15日
 * @version 1.0 
 * @since JDK版本大于等于1.6 
 * @param <T>
 * @param <PK>
 */
public class BaseService<T extends IEntityBean, PK extends Serializable> implements IBaseService<T, PK>{

	protected static final Logger logger = Logger.getLogger(BaseService.class);
	
	@Autowired
	protected IBaseEntityDao<T, PK> dao;
	@Autowired
	private IQueryService queryServ;
	
	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public T find(PK id){
		return this.dao.find(id);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public T find(ICondition condition) {
		return this.dao.find(condition);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> E find(Class<? extends IEntityBean> clazz, PK id) {
		return this.dao.find(clazz, id);
	}
	
	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> List<E> finds(Class<? extends IEntityBean> clazz, ICondition condition) {
		return this.dao.finds(clazz, condition);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public List<T> finds(ICondition condition) {
		return this.dao.finds(condition);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public Paginate<T> findPage(ICondition condition, int pageNo, int pageSize) {
		return this.dao.finds(condition, pageNo, pageSize);
	}

	@Override
	public IQueryService getQueryServ() {
		return this.queryServ;
	}
	
}
